var __request = wx.request;
var Mock = require("./mock.js");
const CONFIG = require('../config.js');

Object.defineProperty(wx, "request", {
  writable: true
});
wx.request = function (config) {
  if (typeof Mock._mocked[config.url] == 'undefined') {
    __request(config);
    return;
  }
  console.log('request url=>', config.url);
  console.log('request data=>', config.data)
  var resTemplate = Mock._mocked[config.url].template;
  var response = { statusCode: 200, data: Mock.mock(resTemplate) };
  console.log('response data=>', response.data)
  if (typeof config.success == 'function') {
    config.success(response)
  }
  if (typeof config.complete == 'function') {
    config.complete(response)
  }
}

var mainData = {
  code: 0,
  r: {
    tabType: {
      tabs: [
        {
          text: '全部',
          channel_id: '1'
        },
        {
          text: '原创馆1',
          channel_id: '2'
        },
        {
          text: '新文学1',
          channel_id: '3'
        },
        {
          text: '读图1',
          channel_id: '4'
        }
      ],
      activeIndex: 0
    },
    bannerList: [
      {
        image_url: '/images/discover-selected.png',
        news_id: '1'
      },
      {
        image_url: '/images/discover-selected.png',
        news_id: '2'
      },
      {
        image_url: '/images/discover-selected.png',
        news_id: '3'
      }
    ],
    topicList: [
      {
        img_url: '/images/discover-selected.png',
        topic_id: '123',
        topic_text: '专题'
      },
      {
        img_url: '/images/discover-selected.png',
        topic_id: '123',
        topic_text: '专题'
      },
      {
        img_url: '/images/discover-selected.png',
        topic_id: '123',
        topic_text: '专题'
      },
      {
        img_url: '/images/discover-selected.png',
        topic_id: '123',
        topic_text: '专题'
      },
    ],
    articleList: [
      {
        news_id: '1',
        img_url: '/images/discover-selected.png',
        title: '2018,遇上最好的自己',
        summary: '愿你在新的一年能够遇见最好的自己,愿你在新的一年能够遇见最好的自己',
        date: '100',
        article_type: '随笔',
        read_num: '123'
      },
      {
        news_id: '2',
        img_url: '/images/discover-selected.png',
        title: '2018,遇上最好的自己',
        summary: '愿你在新的一年能够遇见最好的自己,愿你在新的一年能够遇见最好的自己',
        date: '1',
        article_type: '随笔',
        read_num: '123'

      },
      {
        news_id: '3',
        img_url: '/images/discover-selected.png',
        title: '2018,遇上最好的自己',
        summary: '愿你在新的一年能够遇见最好的自己,愿你在新的一年能够遇见最好的自己',
        date: '1',
        article_type: '随笔',
        read_num: '123'

      }

    ]

  }
}

var articleList = {
  code: 0,
  'r|1-10': [
    {
      news_id: '',
      img_url: '/images/discover-selected.png',
      title: function () {
        return Mock.Random.ctitle(1, 15)
      },
      summary: function () {
        return Mock.Random.ctitle(1, 30)
      },
      'date': '2018-02-23 10:10',
      article_type: '随笔',
      'read_num': '123'
    },
  ]

}
var newsInfo = {
  code: 0,
  r: {
    news_id: '3',
    img_url: '/images/discover-selected.png',
    title: '2018,遇上最好的自己',
    summary: '愿你在新的一年能够遇见最好的自己,愿你在新的一年能够遇见最好的自己',//摘要
    content: "<p><font face=\"Times New Roman\" size=\"3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 一年一度的浙江省高中学生化学竞赛顺利结束。我校学生成绩喜人。沈轻舟、时佳乐等10位同学获得A组一等奖，郭陆英、汪凯翔等17位同学获得A组二等奖，张莹莹等5位同学获得A组三等奖。同时，我校被评为A组集体优胜奖。另外，我校总共有42人获得参加第26届全国高中化学竞赛的资格。</font></p> \n<p><font face=\"Times New Roman\" style=\"font-size:14px;\" size=\"9\"><strong>附：获奖名单</strong></font></p> \n<p><font face=\"Times New Roman\" size=\"3\">一等奖</font></p> \n<p><font face=\"Times New Roman\" size=\"3\">1305 陈豪&nbsp;&nbsp; 1301傅佳明&nbsp;&nbsp; 1301郭飞洋&nbsp;&nbsp; 1307胡晨昱&nbsp; 1307胡为</font></p> \n<p><font face=\"Times New Roman\" size=\"3\">1316贾昱欣 1316沈轻舟&nbsp;&nbsp; 1301时佳乐&nbsp; 1307孙兆予&nbsp;&nbsp; 1301俞杰</font></p> \n<p><font face=\"Times New Roman\" size=\"3\">二等奖</font></p> \n<p><font face=\"Times New Roman\" size=\"3\">1307傅嘉玮 1301郭陆英&nbsp;&nbsp; 1303韩杰枫&nbsp;&nbsp;",//正文
    date: '2018-01-19 10:45',//时间
    read_num: '123',
    reward_num: "100",//打赏金额
    zan_num: "10",//点赞
    foward_num: "10",//转发
    is_zan: true ,// false// 当前用户是否点赞
  }
}


Mock.mock(CONFIG.api + '/getIndexChannels', mainData);
Mock.mock(CONFIG.api + '/getNewsDataPage', articleList);
Mock.mock(CONFIG.api + '/getNewsInfor', newsInfo);
Mock.mock(CONFIG.api + '/uploadUserInfor', {});
Mock.mock(CONFIG.api + '/uploadZan', {});
Mock.mock(CONFIG.api + '/uploadRead', {});
Mock.mock(CONFIG.api + '/uploadForward', {});


module.exports = Mock;
